package model.dao.registerOrder;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import log.MyLogger;
import model.service.ServiceDeviceStatusType;


public class ServiceDeviceStatusTypeDAOImpl {

	String sql = "" ;
	db.dbconnection dbconnection ;
	Connection myConnection ;
	Statement st ;

	public ServiceDeviceStatusType getServiceDeviceStatusTypeById(int serviceDeviceStatusTypeId) {
		ServiceDeviceStatusType serviceDeviceStatusType = new ServiceDeviceStatusType();
		serviceDeviceStatusType.setServiceDeviceStatusType(serviceDeviceStatusTypeId);
		try {
			myConnection= dbconnection.getConnection();
			Statement st = myConnection.createStatement();
			String sql = "SELECT type_name FROM service_device_status_type WHERE service_device_status_type = "+serviceDeviceStatusTypeId;
			ResultSet resultSet = st.executeQuery(sql);
			while(resultSet.next()){
				serviceDeviceStatusType.setTypeName(resultSet.getString("type_name"));
			}
			this.dbconnection.close();
		} catch (Exception e) {
//			MyLogger.Log("ServiceDeviceStatusType.getServiceDeviceStatusTypeById()", e.getMessage());
		}
		return serviceDeviceStatusType;
	}

	public List<ServiceDeviceStatusType> getServiceDeviceStatusTypes() {
		List<ServiceDeviceStatusType> serviceDeviceStatusTypes = new ArrayList<ServiceDeviceStatusType>();
		try {
			myConnection= dbconnection.getConnection();
			Statement st = myConnection.createStatement();
			String sql = "SELECT * FROM service_device_status_type";
			ResultSet resultSet = st.executeQuery(sql);
			while(resultSet.next()){
				ServiceDeviceStatusType serviceDeviceStatusType = new ServiceDeviceStatusType();
				serviceDeviceStatusType.setServiceDeviceStatusType(resultSet.getInt("service_device_status_type"));
				serviceDeviceStatusType.setTypeName(resultSet.getString("type_name"));
				serviceDeviceStatusTypes.add(serviceDeviceStatusType);
			}
			this.dbconnection.close();
		} catch (Exception e) {
//			MyLogger.Log("ServiceDeviceStatusType.getServiceDeviceStatusTypes", e.getMessage());
			return null;
		}
		return serviceDeviceStatusTypes;
	}

}
